<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%
String path = request.getContextPath();  
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
             
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html>
  <head>
    <base href="<%=basePath%>"> 
    
    <title></title>
    	<script type="text/javascript" src="js/jquery-1.8.0.js"></script> 
	<script type="text/javascript">
		function jump (max){
			var pageIndex=document.getElementById("pageIndex").value
			if(pageIndex>0&&pageIndex<=max){
				window.location.href="AdminServlet.do?flag=manage&pageIndex="+pageIndex;
			}
			else{
				alert("输入页码有误,请重新输入");
			}
		}
		function noteShow(note,id){
			if(note.length>5){
				note=note.substr(0,5)+"...";
			}
			$("#note"+id).append(note);
		}
		function  lock(id,state,pageIndex){
			var AdminId='${session_admin.id}';
			if(AdminId==id){
				alert("不能删除或者锁定自己");
			}
			else{
				if(confirm('确定要执行吗')){
				window.location.href="AdminServlet.do?flag=lock&pageIndex="+pageIndex+"&state="+state+"&id="+id;
				}
			}
		}
		
		function checkAll(){
			
			if($("input[name=ck_id]:checked").size()==0)
				alert("请至少选一项!");
			else{
				var list=document.getElementsByName("ck_id");
				for(var i=0;i<list.length;i++){
					if(list[i].checked&&list[i].value=='${session_admin.id}'){
						alert("不能删除自己");
						return ;
					}
				}
				if(confirm('确定要删除所选项吗')){
					form1.submit();	
				}
			}
	    	
	    		
		}
		
		$(function(){
			$("#ch_checkall,#top_ch_checkall").click(function(){
				if(this.checked){
					$("input[name=ck_id]").attr("checked","checked");
				}else{
					$("input[name=ck_id]").removeAttr("checked");
				}		
			});
					
			$("table tr").mouseover(function(){
				$(this).css("background","#D3EAEF");
				$(this).siblings().css("background","white");
			});
		});
	</script>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	
	
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="css/maintable.css" ></link>
  </head>
  
  <body>
    <div class ="div_title">
						<div class="div_titlename"> <img src="images/san_jiao.gif" ><span>管理人员基本信息列表</span></div>
						<div class="div_titleoper">
							<input type="checkbox" id="top_ch_checkall"/> 全选 <a href="admin/admin_add.jsp"> <img src="images/add.gif"/>添加 </a> <a href="javascript:checkAll()"><img src="images/del.gif"/>删除</a> </div>
				 </div>
				 
				 <form action="AdminServlet.do?flag=delAll"  name="form1"  id="from1"  method="post">
				
				 <table class="main_table" >
				       <tr>
				 				<th width="7%"><input type="checkbox" id="ch_checkall" /></th >	<th width="10%">账号</th> 	<th width="7%">状态</th>	<th width="10%">备注</th>  <th>最后更新日期</th> 	<th width="30%">操作</th>
				 		</tr>
				 		
				 		<c:forEach var="admin" items="${adminList }">
				 		<tr>
				 			<td>
				 					<input type="checkbox" name="ck_id" value="${admin.id }" /> 
				 				</td>
				 				<td>${admin.adminName}</td>	
				 				<td>
				 				<c:choose>
								 		<c:when test="${admin.state==2}">已锁定</c:when>
								 		<c:when test="${admin.state==1}"></c:when>	
								</c:choose>
				 				</td>	
				 				<td> <a id="note${admin.id}" title="${admin.note}"><script>noteShow("${admin.note}","${admin.id}")</script></a> </td>	
				 				
				 				<td>${admin.editDate } </td>	
				 				<td>
				 				<c:choose>
				 				<c:when test="${admin.state==2}">
					 				<a href="javascript:lock(${admin.id },1,${page.pageIndex})">解锁</a> |  	
					 			    <a href="javascript:lock(${admin.id },0,${page.pageIndex})">删除</a> 
					 			</c:when>
					 			</c:choose>
					 			<c:choose>
								<c:when test="${admin.state==1}">
									<a href="javascript:lock(${admin.id },2,${page.pageIndex})">锁定</a> |  
					 				<a href="admin/admin_modify.jsp?adminId=${admin.id }&adminName=${admin.adminName}&note=${admin.note}">修改</a> |  	
					 			    <a href="javascript:lock(${admin.id },0,${page.pageIndex})">删除</a> 
								</c:when>	
					 			</c:choose>

				 				</td>
				 		</tr>
				 		</c:forEach>
				</table>
				</form>
				
				<div class="div_page" >
					  <div class="div_page_left">    共有 <label>${page.rowCount}</label> 条记录，当前第 <label>${page.pageIndex}</label> 页，共 <label>${page.pageCount }</label> 页	</div>		
					  <div class="div_page_right" >
					  <c:choose> 	 
					  			<c:when test="${page.hasPre}">
					  			 <a href="AdminServlet.do?flag=manage&pageIndex=1">首页</a>
				  	 			 <a href="AdminServlet.do?flag=manage&pageIndex=${page.pageIndex-1}">上一页</a>
					  			 </c:when>
					  			 <c:otherwise>
									首页
									上一页
								 </c:otherwise>
								 </c:choose>
								 <c:choose> 	
								 <c:when test="${page.hasNext}">
					  			 <a href="AdminServlet.do?flag=manage&pageIndex=${page.pageIndex+1}">下一页</a>
					  			 <a href="AdminServlet.do?flag=manage&pageIndex=${page.pageCount }">尾页</a>
				  	 		   	 </c:when>
								 <c:otherwise>
									下一页
									尾页
								 </c:otherwise>
								 </c:choose>
					  	  <button onclick=jump(${page.pageCount})>转到</button>
					  	 <input type="text" name="pageIndex" id="pageIndex" value="${page.pageIndex}" /> 页
					  	
					   </div>
						
				</div>
  </body>
</html>